package com.lx.utils.biz;


import com.lx.utils.IdWorkGetUtil;

/**
 * Created by lanyxp on 2020/6/18
 */
public final class BizIdWork extends SnowflakeIdWorkerImpl {
    private String bizPrizx;

    /***
     * @param workerId  分布式雪花算法动态workId
     * @param datacenterId 动态datacenterId
     * @param bizPrizx  生成的前缀
     */
    public BizIdWork(long workerId, long datacenterId, String bizPrizx) {
        super(workerId, datacenterId);
        this.bizPrizx = bizPrizx;
    }

    public BizIdWork(long workerId, long datacenterId) {
        super(workerId, datacenterId);
    }

    @Override
    public String nexidBizId() {
        StringBuilder sb = new StringBuilder();
        final String data = bizPrizx.trim().substring(0, 2) + (nexId() & 0x7FF_FFFF_FFFF_FFFFL);
        sb.append(data, 0, 10);
        sb.append(IdWorkGetUtil.checksum(data));
        sb.append(data, 10, 20);
        return sb.toString();
    }
}
